#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
登录的网站需要用户名和密码

'''
import urllib2

username = 'test'
password = '123456'
webserver = '192.168.1.1'

proxy_pass = {"http":"221.2.155.35:8060"}

#构建一个密码管理对象，管理和存储于HTTP请求相关的信息
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()

#添加账户信息，第一个参数realm 没有指定的就是None，后边是siteip,user,pass
password_mgr.add_password(None, webserver, username, password)

#HTTP 基础验证处理器   HTTPBasicAuthHandler
http_authhandler = urllib2.HTTPBasicAuthHandler(password_mgr)

#Proxy 代理处理器
http_proxyhandler = urllib2.ProxyBasicAuthHandler(proxy_pass)

opener = urllib2.build_opener(http_authhandler, http_proxyhandler)

request = urllib2.Request("http://"+webserver+"/")#有问题的话直接输入地址

response = opener.open(request)

print (response.read())